package com.pinyougou.shop.controller;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;

import entity.PageResult;
import entity.Result;

/**
 * 品牌controller
 * @author cui
 *
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
	

	@Reference
	private BrandService brandService;
	/**
	 *
	 * @return
	 */
	@RequestMapping("/findAll")
	public List<TbBrand> findAll(){
		return brandService.findAll();
		
	}
	/**
	 * 分页查询
	 * @return
	 */
	@RequestMapping("/findPage")
	public PageResult<TbBrand> findPage(int page,int rows){
		
		return brandService.findPage(page, rows);
		
	}
	/**
	 * 添加
	 */
	@RequestMapping("/save")
	public Result save(@RequestBody TbBrand tbBrand){
		
		try {
			brandService.save(tbBrand);
			return new Result(true, "添加成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "添加失败");
		}
		
	}	
	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	@RequestMapping("/findOne")
	public TbBrand findOne(long id){
		return brandService.findOne(id);
	}
	/**
	 * 编辑
	 */
	@RequestMapping("/edit")
	public Result edit(@RequestBody TbBrand tbBrand){
		
		try {
			brandService.edit(tbBrand);
			return new Result(true, "编辑成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "编辑失败");
		}
		
	}	
	
	/**
	 * 批量删除
	 */
	@RequestMapping("/del")
	public Result delete(long[] ids){
		
		try {
			brandService.delet(ids);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
		
	}
}
